//
//  OtherSettingsViewController.m
//  CoachsBook
//
//  Created by huiyong li on 2022/8/26.
//

#import "OtherSettingsViewController.h"
#import "OtherModel.h"
#import "OtherSettingCell.h"
#import "OneTabButView.h"
#import "FeedbackViewController.h"
#import "WebViewViewController.h"
@interface OtherSettingsViewController ()<UITableViewDelegate,UITableViewDataSource,OneTabButViewDelegate>

@end

@implementation OtherSettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navgationheadv.titlelabel.text = @"其他设置";
    
    OneTabButView *tabbutview = [[OneTabButView alloc]initWithFrame:CGRectMake(0, APPheight-SafeAreaBottomHeight-65, APPwidth, 65)];
    tabbutview.delegate = self;
    [tabbutview.tabbut setTitle:@"退出登录" forState:UIControlStateNormal];
    [self.view addSubview:tabbutview];
    
    [self getData];
}

- (void)setupUI {
    [super setupUI];

    self.tableView.frame = CGRectMake(0, SafeAreaTopHight, APPwidth, APPheight-SafeAreaTopHight-65);
    
    UIView *HeaderV = [[UIView alloc]initWithFrame:CGRectMake(0, 10, APPwidth, 45)];
    HeaderV.backgroundColor = [UIColor whiteColor];
    
    UIView *myDataLineV = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 3, 15)];
    myDataLineV.backgroundColor = rgba(22, 120, 255, 1);
    myDataLineV.layer.cornerRadius = 2;
    [HeaderV addSubview:myDataLineV];
    UILabel *myDataLab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(myDataLineV.frame)+5, 15, 150, 15)];
    myDataLab.text = @"其他设置";
    myDataLab.textColor = [UIColor blackColor];
    myDataLab.textAlignment = 0;
    myDataLab.font = kPingFangSemibold(16);
    [HeaderV addSubview:myDataLab];
    
    self.tableView.tableHeaderView = HeaderV;
    
}


- (void)getData
{
    NSArray *iconarr = @[@[@"立即分享",@"联系我们",@"问题反馈",@"关于我们",@"检查更新"],@[@"免责声明",@"隐私政策",@"用户协议",@"注销账号"]];
    NSArray *titlearr = @[@[@"立即分享",@"联系我们",@"问题反馈",@"关于我们",@"检查更新"],@[@"免责声明",@"隐私政策",@"用户协议",@"注销账号"]];
    NSArray *contentarr = @[@[@"",@"QQ: 9578254",@"",@"",@""],@[@"",@"",@"",@""]];
    for (NSInteger i=0; i<iconarr.count; i++) {
        NSArray *arr1 = iconarr[i];
        NSArray *arr2 = titlearr[i];
        NSArray *arr3 = contentarr[i];
        NSMutableArray *dataarr = [[NSMutableArray alloc]init];
        for (NSInteger j=0; j<arr1.count; j++) {
            OtherModel *model = [[OtherModel alloc]init];
            model.iconstr = arr1[j];
            model.title = arr2[j];
            model.content = arr3[j];
            model.showArrow = YES;
            model.cellType = 0;
            if (i==0&&j==1) {
                model.showArrow = NO;
                model.cellType = 1;
            }
            [dataarr addObject:model];
        }
        [self.dataArray addObject:dataarr];
    }
    [self.tableView reloadData];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *arr = self.dataArray[section];
    return arr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *arr = self.dataArray[indexPath.section];
    OtherSettingCell *cell=[tableView dequeueReusableCellWithIdentifier:@"OtherSettingCell"];
    if (!cell) {
        cell=[[OtherSettingCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"OtherSettingCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell cellFillWithModel:arr[indexPath.row]];
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0) {
        if (indexPath.row ==0) {
            
        }
        else if (indexPath.row == 2)
        {
            FeedbackViewController *VC = [[FeedbackViewController alloc]init];
            [self.navigationController pushViewController:VC animated:YES];
        }
        else if (indexPath.row == 3)
        {
            
        }
        else if (indexPath.row == 4)
        {
            
        }
    }
    else{
        if (indexPath.row ==0) {
            WebViewViewController *VC = [[WebViewViewController alloc]init];
            VC.webtitle = @"免责声明";
            VC.urlStr = [NSString stringWithFormat:@"%@h5/help/detail-417-1428.html",webUrl];
            [self.navigationController pushViewController:VC animated:YES];
        }
        else if (indexPath.row == 1)
        {
            WebViewViewController *VC = [[WebViewViewController alloc]init];
            VC.webtitle = @"隐私政策";
            VC.urlStr = [NSString stringWithFormat:@"%@h5/help/detail-417-1428.html",webUrl];
            [self.navigationController pushViewController:VC animated:YES];
        }
        else if (indexPath.row == 2)
        {
            WebViewViewController *VC = [[WebViewViewController alloc]init];
            VC.webtitle = @"用户协议";
            VC.urlStr = [NSString stringWithFormat:@"%@h5/help/detail-417-1428.html",webUrl];
            [self.navigationController pushViewController:VC animated:YES];
        }
        else if (indexPath.row == 3)
        {
            
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section==1) {
        return 10;
    }
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==1) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, 10)];
        view.backgroundColor = rgba(245, 245, 250, 1);
        return view;
    }
    return [UIView new];
}


#pragma mark -OneTabButViewDelegate(退出登录)
- (void)OneTabButViewBtnSelectedDelegate:(NSInteger)tag
{
    
}

@end
